package com.lgy.controller;

import com.github.pagehelper.PageInfo;
import com.lgy.pojo.CarBrand;
import com.lgy.pojo.Employee;
import com.lgy.pojo.Repertory;
import com.lgy.service.ICarBrandService;
import com.lgy.service.IRepertoryService;
import com.lgy.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/repertory")
public class RepertoryController {
    @Autowired
    private IRepertoryService repertoryService;
    @Autowired
    private ICarBrandService carBrandService;

    @RequestMapping("/getAllRepertory.do")
    public String getAllRepertory(HttpSession session, Model model,@RequestParam(value = "page",defaultValue = "1") Integer page,@RequestParam(value = "pageSize",defaultValue = "3")Integer pageSize){
        Employee emp = (Employee) session.getAttribute("emp");
        PageInfo<Repertory> pageInfo = repertoryService.findByCompanyId(emp.getCompanyid(),page,pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "AdminRepertoryList";
    }

    //------------------------品牌管理---------------------------------------
    ///brand/tree
    @RequestMapping("/brand/tree.do")
    @ResponseBody
    public ResultData getTreeData(){
        List<Map<String, Object>> list = carBrandService.loadBrandTree();
        return ResultData.ok(list);
    }

    @RequestMapping("/brand/main.do")
    public String brand() {
        return "AdminBrand";
    }

    //brand/list
    @RequestMapping("/brand/list.do")
    @ResponseBody
    public ResultData<List<CarBrand>> getList(){
        List<CarBrand> brandList = carBrandService.findAll();
        return ResultData.ok(brandList);
    }


}
